const isDEV = process.env.NODE_ENV === 'development';
// 基础路径
let publicPath = isDEV ? '/' : './';
module.exports = {
  publicPath,
  lintOnSave: false,
  productionSourceMap: true,
  devServer: {
    open: true,
    overlay: {
      warnings: false,
      errors: true,
    },
    proxy: {
      '/console': {
        target: 'http://115.182.90.205:32117/console/',
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/console': '',
        },
      },
    },
  },
  css: {
    extract: { ignoreOrder: true },
    loaderOptions: {
      // 设置 scss 公用变量文件
      sass: {
        prependData: `@import "@/style/variables.scss";`,
      },
      postcss: {
        plugins: [
          // require("autoprefixer"),
          require('postcss-pxtorem')({
            rootValue: 64,
            propList: ['*'],
          }),
        ],
      },
    },
  },
  chainWebpack: (config) => {
    /**
     * 删除懒加载模块的 prefetch preload，降低带宽压力
     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
     * 而且预渲染时生成的 prefetch 标签是 modern 版本的，低版本浏览器是不需要的
     */
    config.plugins.delete('prefetch').delete('preload');
    // config.optimization.delete('splitChunks');
    // 解决 cli3 热更新失效 https://github.com/vuejs/vue-cli/issues/1559
    config.resolve.symlinks(true);
    // 判断环境加入模拟数据
    const entry = config.entry('app');
    if (process.env.VUE_APP_HAS_MOCK === 'true') {
      entry.add('./mock').end();
    }
    config.module
      .rule('clay')
      .test(/\.clay$/)
      .use('@csii/vx-clay/loader.js')
      .loader('@csii/vx-clay/loader.js')
      .end();
  },
};
